package org.micode.demo.db.dao;

import org.micode.demo.db.domain.dto.SysUserDTO;
import org.micode.libs.dao.base.BaseAllDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户信息(sys_user) 实体类的Dao 
 * 
 * author: wutianbin
 */ 
@Mapper 
public interface SysUserDao extends BaseAllDao<SysUserDTO> {

    // 非常规sql写这里--- xml 自动生成,不再手动在xml中写sql !! 

	@Update("update sys_user set " +
			"  `password` = #{newPassword}, " +
			"  upd_user = #{updUser}, " +
			"  upd_prog = #{updProg}, " +
			"  upd_ip = #{updIp} " +
			"where user_id=#{userId}")
	int resetPwd(@Param("userId") Long userId,
                 @Param("newPassword") String newPassword,
                 @Param("updUser") Long updUser,
                 @Param("updProg") String updProg,
                 @Param("updIp") String updIp);

	@Select("SELECT user_id FROM sys_user " +
			" WHERE del_flag=0 " +
			"   and default_flag != 1 " +
			"   and user_id in (${userIds})")
	@ResultType(Long.class)
	List<Long> listUserIdNotDefault(@Param("userIds") String userIds);

	@Update("update sys_user set " +
			"  del_flag=1, " +
			"  description=login_name, " +
			"  login_name=user_id, " +
			"  upd_user=#{updUser}, " +
			"  upd_prog=#{updProg}, " +
			"  upd_ip=#{updIp} " +
			" where default_flag != 1 " +
			"   and user_id in (${ids})")
	Integer updateDeleteForIds(@Param("ids") String ids,
                               @Param("updUser") Long updUser,
                               @Param("updProg") String updProg,
                               @Param("updIp") String updIp);

}

